﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;

namespace Muel.TypeScriptFacade.TestPlatform.Services
{
    /// <summary>
    /// Performs actions relating to fractions
    /// </summary>
    [WebService]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ScriptService]
    public class FractionService : WebService
    {
        [WebMethod]
        [ScriptMethod]
        public double ConvertFractionToDecimal(Fraction fraction)
        {
            return (double)fraction.Numerator / (double)fraction.Denominator;
        }

        [WebMethod]
        [ScriptMethod]
        public Fraction ConvertDecimalToFraction(double number)
        {
            return new Fraction()
            {
                Numerator = 1,
                Denominator = Convert.ToInt32(1D / number)
            };
        }
    }
}
